package cn.stylefeng.guns.modular.staff.controller;


import cn.stylefeng.guns.modular.staff.entity.Staff;
import cn.stylefeng.guns.modular.staff.pojo.request.StaffRequest;
import cn.stylefeng.guns.modular.staff.service.StaffService;
import cn.stylefeng.roses.kernel.scanner.api.annotation.ApiResource;
import cn.stylefeng.roses.kernel.scanner.api.annotation.GetResource;
import cn.stylefeng.roses.kernel.scanner.api.annotation.PostResource;
import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
import cn.stylefeng.roses.kernel.rule.pojo.response.ResponseData;
import cn.stylefeng.roses.kernel.rule.pojo.response.SuccessResponseData;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * 控制器
 *
 * @author xbz
 * @date 2023/03/31 10:23
 */
@RestController
@ApiResource(name = "员工信息管理")
public class StaffController {

    @Resource
    private StaffService staffService;

    /**
     * 添加
     *
     * @author xbz
     * @date 2023/03/31 10:23
     */
    @PostResource(name = "添加", path = "/staff/add")
    public ResponseData<Staff> add(@RequestBody @Validated(StaffRequest.add.class) StaffRequest staffRequest) {
        staffService.add(staffRequest);
        return new SuccessResponseData<>();
    }

    /**
     * 删除
     *
     * @author xbz
     * @date 2023/03/31 10:23
     */
    @PostResource(name = "删除", path = "/staff/delete")
    public ResponseData<?> delete(@RequestBody @Validated(StaffRequest.delete.class) StaffRequest staffRequest) {
        staffService.del(staffRequest);
        return new SuccessResponseData<>();
    }

    /**
     * 编辑
     *
     * @author xbz
     * @date 2023/03/31 10:23
     */
    @PostResource(name = "编辑", path = "/staff/edit")
    public ResponseData<?> edit(@RequestBody @Validated(StaffRequest.edit.class) StaffRequest staffRequest) {
        staffService.edit(staffRequest);
        return new SuccessResponseData<>();
    }

    /**
     * 查看详情
     *
     * @author xbz
     * @date 2023/03/31 10:23
     */
    @GetResource(name = "查看详情", path = "/staff/detail")
    public ResponseData<Staff> detail(@Validated(StaffRequest.detail.class) StaffRequest staffRequest) {
        return new SuccessResponseData<>(staffService.detail(staffRequest));
    }

    /**
     * 获取列表
     *
     * @author xbz
     * @date 2023/03/31 10:23
     */
    @GetResource(name = "获取列表", path = "/staff/list")
    public ResponseData<List<Staff>> list(StaffRequest staffRequest) {
        return new SuccessResponseData<>(staffService.findList(staffRequest));
    }

    /**
     * 获取列表（带分页）
     *
     * @author xbz
     * @date 2023/03/31 10:23
     */
    @GetResource(name = "分页查询", path = "/staff/page")
    public ResponseData<PageResult<Staff>> page(StaffRequest staffRequest) {
        return new SuccessResponseData<>(staffService.findPage(staffRequest));
    }

}
